package com.dlc.felear.xiaoensale.utils;

import java.util.HashMap;
import java.util.Map;

public class HandleWeightUtil {
    /**
     * 记录上一次称时间
     */
    private Map<String, Long> lastWeight1 = new HashMap<>();
    /**
     * 记录上一次称时间
     */
    private Map<String, Long> lastWeight2 = new HashMap<>();


    public static HandleWeightUtil instance;

    private HandleWeightUtil() {
    }

    public static HandleWeightUtil getInstance() {
        if (instance == null) {
            instance = new HandleWeightUtil();
        }
        return instance;
    }

    /**
     * 获取上上次重量
     *
     * @param num
     * @return
     */
    private long getLastWeight2(String num) {
        if (!lastWeight2.containsKey(num)) {
            lastWeight2.put(num, 0L);
        }
        return lastWeight1.get(num);
    }

    /**
     * 获取上一次重量
     *
     * @param num
     * @return
     */
    private long getLastWeight1(String num) {
        if (!lastWeight1.containsKey(num)) {
            lastWeight1.put(num, 0L);
        }
        return lastWeight1.get(num);
    }

    /**
     * 保存上一次重量
     *
     * @param num
     * @param weight
     */
    public void saveLastWeight(String num, long weight) {
        lastWeight2.put(num, getLastWeight1(num));
        lastWeight1.put(num, weight);
    }

    /**
     * 判断称的稳定
     *
     * @param num
     * @param weight
     * @return
     */
    public boolean checkWeightWd(String num, int weight) {
        return true;
//        int lastWight1 = getLastWeight1(num);
//        int lastWight2 = getLastWeight2(num);
//        if (Math.abs(weight - lastWight1) < 10 && Math.abs(lastWight1 - lastWight2) < 10) {
//            return true;
//        }
//        return false;
    }

}
